package code

import "fmt"

func deferTest11() int {
	i := 1
	defer func() {
		i++
	}()

	// result = i
	return i
}

func Defer11() {
	x := deferTest11()
	// 1
	fmt.Println(x)
}

// 第二种
func deferTest12() *int {
	i := 1
	defer func() {
		i++
	}()
	return &i
}

func Defer12() {
	x := deferTest12()
	// 2
	fmt.Println(*x)
}

// 第三种
func deferTest13() *int {
	i := 1
	defer func(i *int) {
		*i++
	}(&i)
	return &i
}
func Defer13() {
	x := deferTest13()
	// 2
	fmt.Println(*x)
}
